exports.findOne = function (arr, fn) {
  console.log(fn)
  for (let i = 0; i < arr.length; i++) {
    if (fn(arr[i], i, arr)) {
      return arr[i]
    }
  }
  return null
}

exports.findIndex = function (arr, fn) {
  for (let i = 0; i < arr.length; i++) {
    if (fn(arr[i], i, arr)) return i
  }
  return -1
}

exports.findById = function (items, _id, callback) {
  console.log(callback)
  const item = exports.findOne(items, (item) => item._id === _id)
  item && callback && callback(item)
  return item
}

exports.removeOne = function (items, fn) {
  const index = exports.findIndex(items, fn)
  if (index === -1) return null
  const item = items[index]
  items.splice(index, 1)
  return item
}

exports.removeById = function (items, _id, callback) {
  const item = exports.removeOne(items, (item) => item._id === _id)
  item && callback && callback(item)
  return item
}
